/*
 * @Descripttion: 
 * @version: 
 * @Author: jiuguo.qin
 * @Date: 2019-12-20 15:20:48
 * @LastEditors  : jiuguo.qin
 * @LastEditTime : 2020-02-20 11:59:10
 */
#ifndef SCRIPT_H
#define SCRIPT_H
#include "wrk_core.h"
#include <unistd.h>
#include "wrk_record.h"
#include <lua.hpp>
#include <stdbool.h>
// #include "stats.h"

int newPanic(lua_State *L);
lua_State *script_create(char *);

char *script_get_wrk_field(lua_State *L, const char *name);

bool script_resolve(lua_State *, char *, char *);
void script_setup(lua_State *, wrk_core_thread_t *);
void script_done(lua_State *, map<string, series> nodes, map<string, statistics_t *> map_stats);

void script_init(lua_State *, wrk_core_thread_t *);
uint64_t script_delay(lua_State *);
void script_request(lua_State *, wrk_core_connection_t *c);
void script_response(lua_State *, int, wrk_core_connection_t *);
size_t script_verify_request(lua_State *L, wrk_core_connection_t *);

bool script_is_static(lua_State *);
bool script_want_response(lua_State *L);
bool script_has_delay(lua_State *L);
bool script_has_done(lua_State *L);
void script_summary(lua_State *, uint64_t, uint64_t, uint64_t);
void script_errors(lua_State *, stats_errors_t *);

void script_copy_value(lua_State *, lua_State *, int);
int script_parse_url(char *, struct http_parser_url *);

void buffer_append(wrk_core_buffer_t *, const char *, size_t);
void buffer_reset(wrk_core_buffer_t *);
char *buffer_pushlstring(lua_State *, char *);

int newPanic(lua_State *L);

wrk_core_model_t* script_get_model(lua_State *L);


#endif /* SCRIPT_H */
